package com.bluefish.bltuan.action.admin;


import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

import com.bluefish.bltuan.action.AbstractAction;
import com.bluefish.bltuan.tools.ActionUtil;
import com.bluefish.bltuan.tools.user.UserRight;

@Results({
    @Result(name = "home", type = "dispatcher", location = "/page/admin/home.jsp"),
    @Result(name = "login", type = "dispatcher", location = "/page/admin/login.jsp")
})
public class IndexAction extends AbstractAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public HttpHeaders create() {
		return null;
	}

	@Override
	public String destroy() {
		return null;
	}

	@Override
	public String edit() {
		return null;
	}

	@Override
	public HttpHeaders editNew() {
		return null;
	}

	@Override
	public HttpHeaders index() {
		return isLoginManager() ? new DefaultHttpHeaders("home").disableCaching() : 
			new DefaultHttpHeaders("login").disableCaching();
	}

	private boolean isLoginManager(){
		return (ActionUtil.getCurrentUserId() != null && ActionUtil.getCurrentUserRight() == UserRight.ADMIN);
	}
	
	@Override
	public HttpHeaders show() {
		return null;
	}

	@Override
	public String update() {
		return null;
	}

}
